use super::*;

#[derive(Debug, Clone)]
pub struct Table<'a> {
	// uint16	version	Version number (0 or 1—set to 1 in new fonts)
	pub version: u16,
	// uint16	numRanges	Number of records to follow
	// GaspRange	gaspRanges[numRanges]	Sorted by ppem
	pub gasp_ranges: LazyArray16<'a, GaspRange>,
}
impl<'a> FromSlice<'a> for Table<'a> {
	fn parse(data: &'a [u8]) -> Option<Self> {
		let mut s = Stream::new(data);
		Some(Self {
			version: s.read()?,
			gasp_ranges: s.parse_array16()?,
		})
	}
}

#[derive(Debug, Clone, Copy)]
pub struct GaspRange {
	// uint16	rangeMaxPPEM	Upper limit of range, in PPEM
	pub range_max_ppem: u16,
	// uint16	rangeGaspBehavior	Flags describing desired rasterizer behavior.
	pub range_gasp_behavior: RangeGaspBehavior,
}
impl FromData for GaspRange {
	const SIZE: usize = 4;
	fn parse(data: &[u8]) -> Option<Self> {
		let mut s = Stream::new(data);
		Some(Self {
			range_max_ppem: s.read()?,
			range_gasp_behavior: s.read()?,
		})
	}
}

#[derive(Debug, Clone, Copy)]
pub struct RangeGaspBehavior(pub u16);
impl FromData for RangeGaspBehavior {
	const SIZE: usize = 2;
	fn parse(data: &[u8]) -> Option<Self> {
		Some(Self(u16::parse(data)?))
	}
}
impl RangeGaspBehavior {
	pub const GASP_GRIDFIT: RangeGaspBehavior = RangeGaspBehavior(0x0001); //Use gridfitting
	pub const GASP_DOGRAY: RangeGaspBehavior = RangeGaspBehavior(0x0002); // Use grayscale rendering
	pub const GASP_SYMMETRIC_GRIDFIT: RangeGaspBehavior = RangeGaspBehavior(0x0004); // Use gridfitting with ClearType symmetric smoothing Only supported in version 1
	pub const GASP_SYMMETRIC_SMOOTHING: RangeGaspBehavior = RangeGaspBehavior(0x0008); // Use smoothing along multiple axes with ClearType® Only supported in version 1
}
